'use strict';
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import fetch from './fetch';

Vue.use(VueAxios, axios);

const getFetch = (url, data) => {
  return new Promise((resolve, reject) => {
    fetch({url: url, method: 'get', params: data}).then(res => {
      resolve(res)
    }).catch(err => {
      console.log(err);
    })
  })
};

const postFetch = (url, data, file) => {
  return new Promise((resovle, reject) => {

    let option = {url: url, method: 'post', data};
    if (file) {

      let option = {
        url: url,
        method: 'post',
        data,
        headers: {'Content-Type': 'multipart/form-data'}
      };
      fetch(option).then(res => {
        resovle(res);
      }).catch(err => {
        console.log(err);
      })

    } else {
      fetch(option).then(res => {
        resovle(res);
      }).catch(err => {
        console.log(err);
      })
    }
  })
};

const postFetchParams = (url, data) => {
  return new Promise((resolve, reject) => {
    fetch({url: url, method: 'post', params: data}).then(res => {
      resolve(res)
    }).catch(err => {
      console.log(err);
    })
  })
};

export {getFetch, postFetch, postFetchParams}
